package com.woniuxy.joylifeshop.service.serviceImpl;

import com.woniuxy.common.entity.ShopCommodity;
import com.woniuxy.common.entity.ShopCommodityExample;
import com.woniuxy.common.mapper.ShopCommodityMapper;
import com.woniuxy.joylifeshop.exception.MerchantCommodityException;
import com.woniuxy.joylifeshop.service.MerchantCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MerchantCommodityServiceImpl implements MerchantCommodityService {

    @Autowired
    ShopCommodityMapper shopCommodityMapper;
    /**
    * @Author SooYoo
    * @Description 初始化后台的商品情况
    * @Param 
    * @Return 
    **/
    @Override
    public List<ShopCommodity> readMerchantCommodityByCondition(ShopCommodity shopCommodity) {

        try {
            ShopCommodityExample shopCommodityExample = new ShopCommodityExample();
            ShopCommodityExample.Criteria criteria = shopCommodityExample.createCriteria();
            criteria.andMerchantIdEqualTo(shopCommodity.getMerchantId());

            if (shopCommodity.getShopId()!=null && !shopCommodity.getShopId().equals("")) {
                criteria.andShopIdEqualTo(shopCommodity.getShopId());
            }

            if (shopCommodity.getName()!=null && !shopCommodity.getName().equals("")) {
                criteria.andNameEqualTo(shopCommodity.getName());
            }

            List<ShopCommodity> shopCommodities = shopCommodityMapper.selectByExample(shopCommodityExample);

            return shopCommodities;
        } catch (Exception e) {
            e.printStackTrace();
            throw new MerchantCommodityException();
        }
    }
    
    /**
    * @Author SooYoo
    * @Description 删除一条商品数据
    * @Param 
    * @Return 
    **/
    @Override
    public void removeOneCommodity(String information) {

        try {
            shopCommodityMapper.deleteByPrimaryKey(information);
        } catch (Exception e) {
            e.printStackTrace();
            throw new MerchantCommodityException();
        }

    }

    /**
    * @Author SooYoo
    * @Description 通过对象来修改商品信息
    * @Param 
    * @Return 
    **/
    @Override
    public void modifyCommodityByObject(ShopCommodity shopCommodity) {

        try {
            shopCommodityMapper.updateByPrimaryKey(shopCommodity);
        } catch (Exception e) {
            e.printStackTrace();
            throw new MerchantCommodityException();
        }
    }
}
